/**
 * @file   date_time.h
 * @brief  日期时间相关
 * @encode UTF-8
 * @log    date        author      notes
 *         2021.09.17  Jimmy       first version
 */
#ifndef __DATE_TIME_H_ 
#define __DATE_TIME_H_ 

#include <inttypes.h>
#include <unistd.h>
#include <stdio.h>
#include <vector>
#include <chrono>
#include <thread>
#include <ctime>
#include <cstdlib>
#include <ratio>
#include <iostream>
#include <string>

typedef uint64_t TimeStamp;

const uint8_t MAX_AVERAGE_CNT = 16;
// #define mSleep(x)  do { std::this_thread::sleep_for(std::chrono::milliseconds(x)); } while(0)

TimeStamp getSystemRunningTimeSec();
TimeStamp getRealTimeClockMicroSec();
TimeStamp getCurrentTick();

inline TimeStamp now()          { return getCurrentTick(); }
inline TimeStamp nowRtc()       { return getRealTimeClockMicroSec(); }
/* ms延时 */
inline void mSleep(uint16_t x)  { std::this_thread::sleep_for(std::chrono::milliseconds(x)); }

class TimeInterval
{
    public:
        TimeInterval();
        ~TimeInterval();

        /* start */
        TimeStamp mark();
        /* end */
        TimeStamp interval();

    private:
        TimeStamp mLastTime;
        TimeStamp mIntervalMax, mIntervalMin, mIntervalLast;
        TimeStamp mIntervalLastList[MAX_AVERAGE_CNT];
        uint32_t  mIndex;

        TimeStamp update();
};

#endif	/* __DATE_TIME_H_ */